FROM node:18-alpine AS frontend-build

WORKDIR /app

COPY ./belf-consoleWeb/package*.json ./

#RUN npm install --registry=https://registry.npmmirror.com
RUN npm install --legacy-peer-deps --registry=https://registry.npmmirror.com

COPY ./belf-consoleWeb/ .

RUN npm run build:prod


FROM gradle:8.10.2-jdk17 AS backend-build

WORKDIR /app

# Cached gradle dependencies for speed up build
# RUN gradle build --no-daemon -i --stacktrace || return 0

# Set GRADLE_USER_HOME ENV
ENV GRADLE_USER_HOME=/gradle
#COPY ./belf-console/gradle-cache /gradle

#COPY ./belf-base/gradlew ./belf-base/
#COPY ./belf-base/build.gradle ./belf-base/settings.gradle ./belf-base/
#COPY ./belf-base/src ./belf-base/src

COPY ./belf-console/gradlew ./belf-console/gradlew
COPY ./belf-console/build.gradle ./belf-console/settings.gradle ./belf-console/
#COPY ./belf-console/conf ./belf-console/conf
COPY ./belf-console/src ./belf-console/src
COPY --from=frontend-build /app/dist ./belf-console/src/main/resources/static

#RUN gradle -p /app/belf-base jar --no-daemon --info
RUN gradle -p /app/belf-console bootjar --no-daemon --info


FROM openjdk:17-jdk-slim AS runtime


COPY --from=backend-build /app/belf-console/build/libs/belf-console-1.0.jar /belf-console-1.0.jar

EXPOSE 8080

CMD ["java", "-jar", "belf-console-1.0.jar"]